<template>
  <div>
    <div class="app-container">
      <div class="setting">
        <div style="font-size: larger; font-weight: bold; margin: 10px">
          系统配置
        </div>
        <el-form
          :model="numberValidateForm"
          ref="numberValidateForm"
          label-width="200px"
          class="settingForm"
        >
          <el-form-item
            label="文件自动删除间隔(天)"
            prop="day"
            :rules="[
              { required: true, message: '天数不能为空' },
              { type: 'number', message: '天数必须为数字值' },
            ]"
          >
            <el-input
              v-model.number="numberValidateForm.day"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item class="settingBtn">
            <el-button type="primary" @click="submitForm('numberValidateForm')"
              >提交</el-button
            >
            <el-button @click="resetForm('numberValidateForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div style="width: 100%; height: 70vh; overflow: auto">
        <ul
          class="infinite-list"
          style="overflow: auto; display: flex; overflow: auto; flex-wrap: wrap"
        >
          <div
            class="box-form"
            v-for="(folder, index) in folders"
            :key="index"
          >
            <img src="./image/folder.jpg" style="width: 100%; height: auto" />
            <div class="desc">
              <span class="textSpan">文件夹名称：</span>
              <span class="textSpan" style="text-align: center">{{
                folder
              }}</span>
            </div>
            <div class="btnArea">
              <el-button type="danger" class="btn" @click="defectDelDir(folder)"
                >删除</el-button
              >
            </div>
          </div>
        </ul>
      </div>

      <!-- <div class="box-container">
        <div
          style="height: 100%; width: 100%; justify-content: center"
          v-if="folders.length == 0"
        >
          <el-empty :image-size="200"></el-empty>
        </div>
        <div class="box-form" v-for="(folder, index) in folders" :key="index">
          <img src="./image/folder.jpg" style="width: 100%; height: auto" />
          <div class="desc">
            <span class="textSpan">文件夹名称：</span>
            <span class="textSpan" style="text-align: center">{{
              folder
            }}</span>
          </div>
          <div class="btnArea">
            <el-button type="danger" class="btn" @click="defectDelDir(folder)"
              >删除</el-button
            >
          </div>
        </div>
      </div> -->
    </div>
  </div>
</template>
        
    <script>
import * as api from "./api";
export default {
  methods: {},

  data() {
    return {
      folders: [],
      // 配置表单
      numberValidateForm: {
        day: 0,
      },
    };
  },
  mounted() {
    this.getImageFolder();
    api.defectGetDelDay().then((res)=>{
      this.numberValidateForm.day = res.data
    })
  },
  methods: {
    // 查询文件夹
    getImageFolder() {
      api.defectReadDir().then((res) => {
        if (res.data.msg == "fail") {
          this.$message({
            message: "配置路径出错，请联系管理员",
            type: "warning",
          });
          return;
        }
        this.folders = res.data.data;
      });
    },
    // 删除文件夹
    defectDelDir(name) {
      let param = {
        dirName: name,
      };
      this.$confirm("是否确定删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        api.defectDelDir(param).then((res) => {
          if (res == "success") {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.getImageFolder();
          } else {
            this.$message({
              type: "fail",
              message: "删除失败!",
            });
          }
        });
      });
    },
    // 提交按钮
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          api.defectSetDelDay({
            delDay: this.numberValidateForm.day
          }).then(()=>{
            this.$message({
            message: "配置成功！",
            type: "success",
          });
          })
        } else {
          this.$message({
            message: "配置失败！",
            type: "warning",
          });
          return false;
        }
      });
    },
    // 重置按钮
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },

  },
};
</script>
      
  <style scoped lang="scss">
.app-container {
  //padding: 20px;
  display: flex;
  min-height: 180px;
  padding: 20px 20px 0px 20px;
  margin-right: auto;
  margin-left: auto;
  flex-wrap: wrap;
}

.box-container {
  display: flex;
  height: 68vh;
  width: 100%;
  // flex-wrap: wrap;
  flex-flow: wrap;
  overflow: auto;
  .box-form {
    position: relative;
    border-top: 0;
    margin-bottom: 15px;
    margin-right: 20px;
    width: 11%;
    height: 36%;
    background: #fff;
    border-radius: 0;
    padding: 10px;
    -webkit-transition: 0.5s;
    transition: 0.5s;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-direction: column;
    flex-direction: column;
    border: 1px solid #dce3e6;
    border-radius: 6px;
    -webkit-box-shadow: 0px 5px 30px rgba(0, 0, 0, 0.05);
    box-shadow: 0px 5px 30px rgba(0, 0, 0, 0.05);

    .desc {
      padding: 8px;
      margin-top: 10px;
      background: rgba(246, 246, 246, 1);
      height: 60px;

      .textSpan {
        width: 100%;
        display: inline-block;
      }
    }
    .btnArea {
      margin-top: 10px;
      .btn {
        width: 100%;
      }
    }
  }
}

.setting {
  width: 100%;
  height: 20vh;
  margin-bottom: 10px;
  background: #fff;
  border-radius: 4px;
  padding: 5px;
  display: block;
  border: 1px solid #dce3e6;
  border-radius: 4px;
  -webkit-box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.05);
  box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.05);
  .settingForm {
    font-size: 20px;
    position: relative;
    width: 100%;
    height: 18vh;
  }
  .settingBtn {
    position: absolute;
    bottom: 30px;
    left: -180px;
  }
}
.box-form {
    position: relative;
    border-top: 0;
    margin-bottom: 15px;
    margin-right: 20px;
    width: 11%;
    height: 36%;
    background: #fff;
    border-radius: 0;
    padding: 10px;
    -webkit-transition: 0.5s;
    transition: 0.5s;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-direction: column;
    flex-direction: column;
    border: 1px solid #dce3e6;
    border-radius: 6px;
    -webkit-box-shadow: 0px 5px 30px rgba(0, 0, 0, 0.05);
    box-shadow: 0px 5px 30px rgba(0, 0, 0, 0.05);
    flex-basis: calc(100% / 8);

    .desc {
      padding: 8px;
      margin-top: 10px;
      background: rgba(246, 246, 246, 1);
      height: 60px;

      .textSpan {
        width: 100%;
        display: inline-block;
      }
    }
    .btnArea {
      margin-top: 10px;
      .btn {
        width: 100%;
      }
    }
  }
::v-deep .el-form-item__label {
  font-size: 17px;
}
::v-deep .el-input__inner {
  width: 20%;
  margin-left: 10px;
}
</style>